package com.kotiln.lgc.sunnyweather.logic.dao

import android.content.Context
import androidx.core.content.edit
import com.google.gson.Gson
import com.kotiln.lgc.sunnyweather.MyApplication
import com.kotiln.lgc.sunnyweather.logic.model.Place

/**
 *@fileName PlaceDao
 *@date2020/12/2  16:44
 *@author PlaceDao$
 *@describe TODO
 *@desc
 */
object PlaceDao{
    private fun sharedPreferences()=MyApplication.context.getSharedPreferences("sunny_weather",
        Context.MODE_PRIVATE)

    fun savePlace(place: Place)
    {
        sharedPreferences().edit {
            putString("place",Gson().toJson(place))
        }
    }

    fun getSavePlace():Place{
        val placeJson=sharedPreferences().getString("place","")
        return Gson().fromJson(placeJson,Place::class.java)
    }

    fun isPlaceSaved() = sharedPreferences().contains("place")
}